<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<c:url value="/" />">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>文章管理</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery-1.11.3.js"></script>
    <script src="js/bootstrap-min.3.3.5.js"></script>
    <script src="js/bootstrap-paginator.js"></script>
</head>
<body>
<jsp:include page="../include/top.jsp"></jsp:include>
<div class="container">
    <hr/>
    <h3>文章列表 <a href="<%=basePath%>admin/users/add" type="button" class="btn btn-primary btn-sm">添加</a></h3>
    <!-- 如果用户列表为空 -->
    <c:if test="${empty newsList}">
        <div class="alert alert-warning" role="alert">
            <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> 没有数据
        </div>
    </c:if>

    <!-- 如果列表非空 -->
    <c:if test="${!empty newsList}">
        <table class="table table-bordered table-striped">
            <tr>
                <th>ID</th>
                <th>标题</th>
                <th>来源</th>
                <th>抓取时间</th>
                <th>类别</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${newsList}" var="news">
                <tr>
                    <td>${news.id}</td>
                    <td>${news.title}</td>
                    <td>${news.source}</td>
                    <td>${news.createtime}</td>
                    <td>${news.article_type}</td>
                    <td>
                        <a href="<%=basePath%>article/show/${news.id}" type="button" class="btn btn-sm btn-success">详情</a>
                        <a href="<%=basePath%>article/update/${news.id}" type="button" class="btn btn-sm btn-warning">修改</a>
                        <a href="<%=basePath%>article/delete/${news.id}" type="button" class="btn btn-sm btn-danger">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <ul class="pagination pagination-lg" id="paginator" style=" margin: 0; float:right;">
        </ul>
    </c:if>

</div>
<script type='text/javascript'>
    var options = {
        bootstrapMajorVersion: 3, //bootstrap版本
        size: 'normal',
        itemTexts: function (type, page, current) {
            switch (type) {
                case "first":
                    return "首页";
                case "prev":
                    return "<i class='fa fa-caret-left'></i> 上一页";
                case "next":
                    return "下一页 <i class='fa fa-caret-right'></i>";
                case "last":
                    return "末页";
                case "page":
                    return page;
            }
        },
        tooltipTitles: function (type, page, current) {
            switch (type) {
                case "first":
                    return "首页";
                case "prev":
                    return "上一页";
                case "next":
                    return "下一页";
                case "last":
                    return "末页";
                case "page":
                    return "第" + page + "页";
            }
        },
        pageUrl: function (type, page, current) {
            return "<%=basePath%>article/list?page=" + page; //跳转到选定页面
        },
        numberOfPages: 6, //显示“第几页”的选项数目
        currentPage: ${pageNumber}, //当前页数
        totalPages: ${totalPageNumber} //总页数
    }

    $('#paginator').bootstrapPaginator(options);
</script>

</body>
</html>